package com.flower8.service.impl;

import com.flower8.dao.CardDao;
import com.flower8.dto.CardCostRecordDto;
import com.flower8.dto.CardDto;
import com.flower8.dto.CardMonthBillDto;
import com.flower8.model.Card;
import com.flower8.service.CardService;
import com.flower8.sysconfig.constants.SysConstants;
import com.flower8.utils.AES;
import com.flower8.utils.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: tanglin
 * @Date: 2019/09/03 14:21
 * @Version: 1.0
 */
@Service
public class CardServiceImpl implements CardService {

    @Autowired
    private CardDao cardDao;

    @Override
    public List<CardDto> getCardList(Map params) throws Exception {
        List<CardDto> cardList = cardDao.getCardList(params);
        for (CardDto card : cardList) {
            card.setEmailPwd(AES.AESDecode(SysConstants.EMAIL_PRIVATE_KEY,card.getEmailPwd()));
            String selfPwd = card.getEmailPwdSelf();
            if (selfPwd != null && !"".equals(selfPwd)){
                card.setEmailPwdSelf(AES.AESDecode(SysConstants.EMAIL_PRIVATE_KEY,selfPwd));
            }
        }
        return cardList;
    }

    @Override
    public int getCardListCount(Map params) throws Exception {
        return cardDao.getCardListCount(params);
    }

    /**
     * 根据用户id查询银行卡
     * @param pd
     * @return
     */
    @Override
    public List<CardDto> getCardByUserId(PageData pd)throws Exception {
        List<CardDto> cardList = cardDao.getCardByUserId(pd);
        for (CardDto card : cardList) {
            card.setEmailPwd(AES.AESDecode(SysConstants.EMAIL_PRIVATE_KEY,card.getEmailPwd()));
            String selfPwd = card.getEmailPwdSelf();
            if (selfPwd != null && !"".equals(selfPwd)){
                card.setEmailPwdSelf(AES.AESDecode(SysConstants.EMAIL_PRIVATE_KEY,selfPwd));
            }
        }
        return cardList;
    }

    /**
     * 根据用户id查询银行卡数量
     * @param pd
     * @return
     */
    @Override
    public int getCardByUserIdCount(PageData pd)throws Exception {
        return cardDao.getCardByUserIdCount(pd);
    }

    /**
     * 查询信用卡消费记录
     * @param pd
     * @return
     * @throws Exception
     */
    @Override
    public List<CardCostRecordDto> getCardCostRecord(PageData pd) throws Exception {
        return cardDao.getCardCostRecord(pd);
    }

    /**
     * 查询信用卡消费记录总数
     * @param pd
     * @return
     * @throws Exception
     */
    @Override
    public int getCardCostRecordCount(PageData pd) throws Exception {
        return cardDao.getCardCostRecordCount(pd);
    }

    /**
     * 查询信用卡月度账单记录
     * @param pd
     * @return
     * @throws Exception
     */
    @Override
    public List<CardMonthBillDto> getCardMonthRecord(PageData pd) throws Exception {
        return cardDao.getCardMonthRecord(pd);
    }

    /**
     * 查询信用卡月度账单记录总数
     * @param pd
     * @return
     * @throws Exception
     */
    @Override
    public int getCardMonthRecordCount(PageData pd) throws Exception {
        return cardDao.getCardMonthRecordCount(pd);
    }
}
